package com.chen.blue.controller.admin.business;


import com.chen.blue.annotation.permission.DataPermission;
import com.chen.blue.domain.dto.business.ContestApplyDto;
import com.chen.blue.domain.dto.business.ContestPersonInfoDto;
import com.chen.blue.domain.dto.business.update.ContestApplyDtoEdit;
import com.chen.blue.domain.query.business.ContestApplyQuery;
import com.chen.blue.domain.query.system.DeptQuery;
import com.chen.blue.domain.vo.business.ContestApplyVo;
import com.chen.blue.domain.vo.system.DeptVo;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.DataResult;
import com.chen.blue.result.R;
import com.chen.blue.service.business.IContestApplyService;
import com.chen.blue.service.business.IContestPersonInfoService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 竞赛表 前端控制器
 * </p>
 *
 * @author CLT
 * @since 2024-05-26
 */
@ApiSort(995)
@Api(tags = "申报管理-赛事列表模块")
@Validated
@RestController
@RequestMapping("/contest")
public class ContestApplyController {

    @Resource
    private IContestApplyService iContestApplyService;

    @ApiOperation(value = "多条件查询竞赛", notes = "多条件查询竞赛")
    @DataPermission
    @PostMapping("/query")
    public R<DataResult<List<ContestApplyVo>>> query(@RequestBody ContestApplyQuery contestApplyQuery) throws DtoNullException {

        return R.success(iContestApplyService.queryContestApply(contestApplyQuery));

    }

    @ApiOperation(value = "ID查询竞赛", notes = "ID查询竞赛")
    @GetMapping("/queryById/{id}")
    public R<DataResult<Map<String, Object>>> queryById(@PathVariable("id") Long applyId) throws DtoNullException {

        return R.success(iContestApplyService.queryContestApplyById(applyId));

    }

    @PreAuthorize("hasRole('ROLE_teacher')")
    @ApiOperation(value = "竞赛人员信息填报或修改", notes = "竞赛人员信息填报或修改")
    @PostMapping("/person/add/{id}")
    public R addContestPersonInfo(@PathVariable("id") Long applyId, @RequestBody List<ContestPersonInfoDto> data) throws DtoNullException {

        return R.success(iContestApplyService.addRelationPersonInfo(applyId, data));

    }

    @ApiOperation(value = "查询所有部门", notes = "查询所有部门")
    @PostMapping("/dept/query")
    public R<DataResult<List<DeptVo>>> queryDept(@RequestBody DeptQuery deptQuery) throws DtoNullException {

        return R.success(iContestApplyService.queryDept(deptQuery, false));

    }

}

